#include "weekday.h"

//判断输入是否有效
int is_valid(int year, int month, int day) {
  if (year < 1583) {
    return 0;
  }

  return 1;
}

int calc_weekday(int year, int month, int day) {
  int week;

  if (!is_valid(year, month, day)) {
    return -1;
  }

  //使用蔡勒公式计算
  if (month == 1 || month == 2) //判断month是否为1或2　
    year--, month += 12;
  int c = year / 100;
  int y = year - c * 100;
  week = y + y / 4 + c / 4 - 2 * c + 26 * (month + 1) / 10 + day - 1;
  while (week < 0)
    week += 7;
  week %= 7;

  return week;
}
